<?php
/**
 * Created by PhpStorm.
 * User: denh
 * Date: 17/2/22
 * Time: 下午1:51
 */
namespace bs\wxNews;

require_once _LHDir. 'bs/wxNews/Base.php';

#课程一天前预告
class Course_1 extends Base {

    function sendNews($userArray) {
        static $i = 0;
        if ($i == 0) {
            $this->addPictureTextNews($userArray);
            $this->addTemplateNews($userArray);
        }
        $i++;
        $this->sendPicTextTemplateNews($userArray);
    }

    /**同时发送图文和模板消息
     * @param $userArray

    function sendPicTextTemplateNews($userArray) {
        $isOk = $this->sendPictureTextNews($userArray);
        $this->sendTemplateNews($userArray);
    }*/

    function addPictureTextNews($userArray = null) {
        $pictureUrl =  G_SITE_BASE.'/business/' . 'img/logoRed2.png';
        $this->pictureTextNews = new \Cbo图文消息列表();
        $this->pictureTextNews->ft添加图文消息 ('💻视频课程', '', $this->doTemplate->get_url(), '');
        $this->pictureTextNews->ft添加图文消息($this->doTemplate->get_pt_title(), '', $this->doTemplate->get_url(), $pictureUrl);

    }

    function addTemplateNews($userArray = null) {
        global $G_CONFIG;
        $this->templateNews->templateId = $G_CONFIG['模板消息ID']['课程提醒'];
        $this->templateNews->url = $this->doTemplate->get_url();
        $this->templateNews->data = array(
            'first'=>array('value' => $this->doTemplate->get_template_first()."\n", 'color' => '#999999'),
            'keyword1'=>array('value' => $this->doTemplate->get_template_keyword1(), 'color' => '#d0274a'), //课程
            'keyword2'=>array('value' => $this->doTemplate->get_template_keyword2(), 'color' => '#333333'), //参加人
            'remark'=>array('value' => "\n".$this->doTemplate->get_template_remark(), 'color' => '#5c94c6')
        );
    }
}

#课前通知
class Course_2 extends Base {

    /**给报名的用户发消息
     * @param int $limit
     * @param int $size
     */
    function sendToSignUpUser() {

        $doNews = new \DoNews_pictext_template();
        $doNews->loadById($this->newsId);
        $where = $doNews->get_note();

        $do = new \DoCourse_signup();
        $do->set_courseId($where);
        $do->set_status(0);
        $users = $do->where($do->data)->rows();

        foreach ($users as $k => $v) {
            if (!$this->is_received($v['openID'])) {
                $this->sendNews($v);
            }
        }
    }

    function sendNews($userArray) {
        static $i = 0;
        if ($i == 0) {
            $this->addPictureTextNews($userArray);
            $this->addTemplateNews($userArray);
        }
        $i++;
        $this->sendPicTextTemplateNews($userArray);
    }

    /**同时发送图文和模板消息
     * @param $userArray
    function sendPicTextTemplateNews($userArray) {
        $isOk = $this->sendPictureTextNews($userArray);
        $this->sendTemplateNews($userArray);
    }*/

    function addPictureTextNews($userArray = null) {
        $pictureUrl =  G_SITE_BASE.'/business/' . 'img/logoRed2.png';
        $this->pictureTextNews->ft添加图文消息 ('💻视频课程将要开始', '', $this->doTemplate->get_url(), '');
        $this->pictureTextNews->ft添加图文消息(
            '课程《'.$this->doTemplate->get_pt_title().'》将要开始，请按时进入课堂',
            '',
            $this->doTemplate->get_url(),
            $pictureUrl
        );
    }

    function addTemplateNews($userArray = null) {
        global $G_CONFIG;
        $this->templateNews->templateId = $G_CONFIG['模板消息ID']['课程开课通知'];
        $this->templateNews->url = $this->doTemplate->get_url();
        $this->templateNews->data = array(
            'userName' => array('value' => $userArray['name'], 'color' => '#173177'),
            'courseName' => array('value' => $this->doTemplate->get_template_keyword1(), 'color' => '#173177'),
            'date' => array('value' => $this->doTemplate->get_template_keyword2(), 'color' => '#173177'),
            'remark' => array('value' => "\n" . $this->doTemplate->get_template_remark(), 'color' => '#173177')
        );
    }
}

